var e = require("../../../api.js"), r = getApp(), a = require("../../../utils/function.js");

Page({
    data: {
        img: a.userImg,
        order: null,
        page: 1,
        order_url: [ "/pages/driverOrder/orderedStatus/orderedStatus", "/pages/driverOrder/orderGoing/orderGoing", "/pages/driverOrder/bill/bill", "/pages/driverOrder/orderDetail/orderDetail", "/pages/driverOrder/orderedStatus/orderedStatus" ]
    },
    onLoad: function(e) {
        e.uid && r.shareCouponsMessage(e.uid);
    },
    report: function(e) {
        var r = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/driverOrder/insuranceReport/index?id=" + r
        });
    },
    intoPageHandler: function(e) {
        return 0 != e.currentTarget.dataset.delete ? (wx.showToast({
            title: "该订单已取消",
            icon: "none"
        }), !1) : 4 == e.currentTarget.dataset.start ? (a.intoPageHandler(e.currentTarget.dataset.skip + "?orderstart=1&order_no=" + e.currentTarget.dataset.order_no), 
        !1) : void a.intoPageHandler(e.currentTarget.dataset.skip + "?order_no=" + e.currentTarget.dataset.order_no);
    },
    goOrderDetail: function(e) {
        e.currentTarget.dataset.id;
        var r = e.currentTarget.dataset.index, a = this.data.order;
        1 == a[r].is_send && 1 == a[r].initiate && 1 == a[r].is_pay ? wx.navigateTo({
            url: "/pages/userOrder/orderDetail/orderDetail?order_no=" + e.currentTarget.dataset.id 
        }) : 0 == a[r].is_send && 0 == a[r].apply_delete ? wx.navigateTo({
            url: "/pages/map/orderAndDriverGoing/orderAndDriverGoing?order_no=" + e.currentTarget.dataset.id
        }) : 1 == a[r].apply_delete ? wx.navigateTo({
            url: "../orderDetail/orderDetail?order_no=" + e.currentTarget.dataset.id
        }) : 0 == a[r].apply_delete && 0 == a[r].is_service ? wx.navigateTo({
            url: "../../map/getOrderNotGoing/getOrderNotGoing?order_no=" + e.currentTarget.dataset.id
        }) : 0 == a[r].apply_delete && 1 == a[r].is_service ? wx.navigateTo({
            url: "../../map/orderGoing/orderGoing?order_no=" + e.currentTarget.dataset.id
        }) : 0 == a[r].apply_delete && 2 == a[r].is_service ? wx.navigateTo({
            url: "/pages/pay/paidOrder/paidOrder?order_no=" + e.currentTarget.dataset.id
        }) : wx.navigateTo({
            url: "/pages/userOrder/orderDetail/orderDetail?order_no=" + e.currentTarget.dataset.id
        });
    },
    deleteOrderHandler: function() {
        var e = this;
        wx.showModal({
            title: "删除订单",
            content: "确认是否删除所有订单",
            success: function(r) {
                r.confirm && e.setData({
                    order: []
                });
            },
            fail: function() {}
        });
    },
    onReady: function() {},
    onShow: function() {
        var a = this;
        r.request({
            url: e.order_branch.getTodayOrder,
            method: "post",
            data: {
                p: 10
            },
            success: function(e) {
                1 == e.code && a.setData({
                    order: e.data.data
                });
            }
        });
    },
    onReachBottom: function() {
        var a = this, t = this.data, d = t.order, o = t.page;
        wx.showLoading({});
        var n = o + 1;
        this.setData({
            page: n
        }), r.request({
            url: e.order_branch.getTodayOrder,
            method: "post",
            data: {
                page: n,
                p: 10
            },
            success: function(e) {
                if (wx.hideLoading(), 1 == e.code && 0 != e.data.data.length) {
                    for (var r = 0; r < e.data.data.length; r++) d.push(e.data.data[r]);
                    console.log(e.data.data, "22222"), a.setData({
                        order: d
                    });
                }
            }
        });
    },
    onShareAppMessage: function() {
        return {
            title: r.shareAppMessage().title,
            imageUrl: r.shareAppMessage().imageUrl,
            desc: r.shareAppMessage().desc,
            path: r.shareAppMessage().path
        };
    },
    onHide: function() {
        this.setData({
            page: 1
        }), console.log(this.data.page);
    },
    onUnload: function() {
        console.log(this.data.page);
    }
});